package com.liang.maogouyuyin.ui.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.liang.maogouyuyin.ui.fragment.InstructionFragment
import com.liang.maogouyuyin.ui.fragment.QuotationsFragment

class InteractFragmentAdapter(fragmentActivity: FragmentActivity): FragmentStateAdapter(fragmentActivity) {

    private val list = ArrayList<Fragment>()

    override fun getItemCount(): Int {
        return 2
    }

    override fun createFragment(position: Int): Fragment {
        return when (position) {
            0 -> {
                val fragment = QuotationsFragment()
                list.add(fragment)
                fragment
            }
            1 -> {
                val fragment = InstructionFragment()
                list.add(fragment)
                fragment
            }
            else -> throw IllegalArgumentException()
        }
    }

    fun getFragment(position: Int): Fragment {
        return list[position]
    }

    fun getListSize(): Int {
        return list.size
    }
}